<%@page import="monster.comm.util.SpringApplicationContextFactory"%>
<%@page import="monster.flight.admin.manager.service.admin.Flight_infoService"%>
<%@page import="monster.flight.comm.util.FlightFactory"%>
<%@page import="monster.comm.util.DateUtil"%>
<%@page import="monster.flight.comm.entity.vo.FlightBay"%>
<%@page import="sun.jdbc.rowset.CachedRowSet"%>
<%@page import="monster.flight.comm.entity.vo.Flight_info"%>
<%@page import="monster.comm.database.DBManager"%>
<%@page import="monster.comm.util.SysConstant"%>
<%@page import="monster.comm.util.UserService"%>
<%@page import="monster.comm.util.Tool"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%
String name=Tool.getRequest("name",request);//必传参数
String bg_date=Tool.getRequest("bg_date",request);//必传参数
String ed_date=Tool.getRequest("ed_date",request);//必传参数
String list="";

UserService user = (UserService) session.getAttribute(SysConstant.SESSION_NAME);//获得session里面的登陆信息
if(1==2){
	out.println("{\"id\":-100,\"name\":\"没有登录\"}");
	return;
}else{
	try{
		DBManager db = new DBManager();
	
		String sql = "SELECT a.STAFF_SN,a.STAFF_NAME,STAFF_ID,SQUADRON_NO,UNIT_NO,'驻站' as xz,'' as hb, "
					+"	b.STATION_PLACE as place ,STATION_START_DATETIME as bg_date, "
					+" STATION_END_DATETIME as ed_date,OP_NAME,OP_SN,OP_DATETIME "
					+" from STAFF_INFO a inner join STAFF_STATION_PLAN b on a.staff_sn=b.staff_sn where 1=1 ";	
		        if(!"".equals(name)){
		        	sql+=" and a.STAFF_NAME like '%"+name+"%'";
		        }
		        if(!"".equals(bg_date)){
		        	sql+=" and STATION_START_DATETIME >='"+bg_date+"'";
		        }
		        if(!"".equals(ed_date)){
		        	sql+=" and STATION_END_DATETIME <= '"+ed_date+"'";
		        }
		        sql += "union SELECT a.STAFF_SN,a.STAFF_NAME,STAFF_ID,SQUADRON_NO,UNIT_NO,'随机' as xz,FLIGHT_NO as hb, "
					+"	BAY as place,RAN_START_DATETIME as bg_date, "
					+"   RAN_END_DATETIME as ed_date,OP_NAME,OP_SN,OP_DATETIME "
					+" from STAFF_INFO a inner join STAFF_RAN_PLAN b on a.staff_sn=b.staff_sn where 1=1 ";	
		        if(!"".equals(name)){
		        	sql+=" and a.STAFF_NAME like '%"+name+"%'";
		        }
		        if(!"".equals(bg_date)){
		        	sql+=" and RAN_START_DATETIME >='"+bg_date+"'";
		        }
		        if(!"".equals(ed_date)){
		        	sql+=" and RAN_END_DATETIME <= '"+ed_date+"'";
		        }
		        sql += "union SELECT a.STAFF_SN,a.STAFF_NAME,STAFF_ID,SQUADRON_NO,UNIT_NO,'休假其它' as xz,'' as hb, "
					+"	HOLIDAY_CLASS as place,HOLIDAY_START_DATETIME as bg_date, "
					+"   HOLIDAY_END_DATETIME as ed_date,OP_NAME,OP_SN,OP_DATETIME "
					+" from STAFF_INFO a inner join STAFF_HOLIDAY_PLAN b on a.staff_sn=b.staff_sn where 1=1 ";	
		        if(!"".equals(name)){
		        	sql+=" and a.STAFF_NAME like '%"+name+"%'";
		        }
		        if(!"".equals(bg_date)){
		        	sql+=" and HOLIDAY_START_DATETIME >='"+bg_date+"'";
		        }
		        if(!"".equals(ed_date)){
		        	sql+=" and HOLIDAY_END_DATETIME <= '"+ed_date+"'";
		        }
		String ret="";
		CachedRowSet cr = db.getRowSet(sql);
	
		while(cr.next()){	
			String STAFF_SN=Tool.getRsValue(cr,"STAFF_SN");
			String STAFF_ID=Tool.getRsValue(cr,"STAFF_ID");
			String STAFF_NAME=Tool.getRsValue(cr,"STAFF_NAME");		
			String SQUADRON_NO=Tool.getRsValue(cr,"SQUADRON_NO");
			String UNIT_NO=Tool.getRsValue(cr,"UNIT_NO");
			String xz=Tool.getRsValue(cr,"xz");
			String hb=Tool.getRsValue(cr,"hb");
			String place=Tool.getRsValue(cr,"place");
			String sbg_date=Tool.getRsValue(cr,"bg_date");
			String sed_date=Tool.getRsValue(cr,"ed_date");
			String OP_NAME=Tool.getRsValue(cr,"OP_NAME");
			String OP_SN=Tool.getRsValue(cr,"OP_SN");
			String OP_DATETIME=Tool.getRsValue(cr,"OP_DATETIME");
			ret+="{";
			ret+="\"STAFF_SN\":\""+STAFF_SN+"\",";
			ret+="\"STAFF_ID\":\""+STAFF_ID+"\",";
			ret+="\"STAFF_NAME\":\""+STAFF_NAME+"\",";
			ret+="\"SQUADRON_NO\":\""+SQUADRON_NO+"中队\",";
			ret+="\"UNIT_NO\":\""+UNIT_NO+"分队\",";			
			ret+="\"xz\":\""+xz+"\",";
			ret+="\"hb\":\""+hb+"\",";
			ret+="\"place\":\""+place+"\",";
			ret+="\"bg_date\":\""+sbg_date+"\",";
			ret+="\"ed_date\":\""+sed_date+"\",";
			ret+="\"OP_NAME\":\""+OP_NAME+"\",";
			ret+="\"OP_DATETIME\":\""+OP_DATETIME+"\",";
			ret+="\"OP_SN\":\""+OP_SN+"\"";
			ret+="},";
		}
		if(ret.length()>0){
			ret=ret.substring(0,ret.length()-1);
		}
		list="{\"id\":100,\"list\":["+ret+"]}";
	}catch(Exception e){
		 e.printStackTrace();
		 list="{\"id\":-200,\"name\":\"程序异常\"}";
	}
	
	out.println(list);

}
%>
